<?php
class newsModel extends BaseModel
{   
    protected $table = 'article';
    public function getPageNewsList($page,$page_num,$where=null){
        if(!empty($where)){
            $data = $this->feild('COUNT(*) AS num')->where($where)->select();
        }else {
            $data = $this->feild('COUNT(*) AS num')->select();
        }
        if(!empty($data)){
            $count = $data[0]['num'];
        }else {
            $count = 0;
        }
        if(empty($count)){
            return array('count'=>0,'value'=>array());
        }
        $start = ($page-1)*$page_num;
        if(!empty($where)){
            $result = $this->where($where)->order('publish_time')->limit("$start,$page_num")->select();
        }else {
            $result = $this->order('publish_time DESC')->limit("$start,$page_num")->select();
        }
        if(empty($result)){
            $arr = array('count'=>0,'value'=>$result);
        }else{
            $arr = array('count'=>$count,'value'=>$result);
        }
        return $arr;
    }
    public function getNewsById($id){
        if(empty($id)){
            return false;
        }
        $re = $this->where("id='{$id}'")->select();
        if(empty($re)){
            return array();
        }else {
            return $re[0];
        }
    }
}